﻿using System.Collections.ObjectModel;
using System.Linq;
using XenoGears.Reflection.Attributes.Snippets;
using XenoGears.Assertions;
using XenoGears.Functional;

namespace Jink.Core.Handlers.Annotations
{
    internal static class HandlersRegistry
    {
        public static ReadOnlyCollection<Handler> All
        {
            get
            {
                var snippets = SnippetRegistry.For<HandlesAttribute>();
                return snippets.Select(s => new Handler(
                    s.Code, 
                    s.TypeAnnotation.AssertCast<HandlerAttribute>(),
                    s.MethodAnnotation.AssertCast<HandlesAttribute>())
                ).ToReadOnly();
            }
        }
    }
}
